/*
 * 时间段表示类
 * Copyright (C) 2009  YuLicheng
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sysmo.server.util;

import java.util.Date;

/**
 * 表示由起始时间和结束时间构成的时间段。
 *
 * @author YuLicheng
 */
public class TimeInterval {

    private Date startTime;
    private Date endTime;

    /**
     * 构建时间段对象。
     *
     * @param startTime 时间段起始时间。
     * @param endTime 时间段结束时间。
     */
    public TimeInterval(Date startTime, Date endTime) {
        this.startTime = startTime;
        this.endTime = endTime;
    }

    /**
     * 获取时间段起始时间。
     *
     * @return 起始时间。
     */
    public Date getStartTime() {
        return startTime;
    }

    /**
     * 获取时间段结束时间。
     *
     * @return 结束时间。
     */
    public Date getEndTime() {
        return endTime;
    }

    /**
     * 判断某一时间点是否在当前的时间段范围之内。
     *
     * @param time 要判断的时间点。
     * @return 若在当前的时间段范围之内则返回true，否则返回false。
     */
    public boolean isInTimeInterval(Date time) {
        return time.after(startTime) && time.before(endTime);
    }
}
